package com.shuqi.activity.adapter;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shuqi.activity.BookSearchParentActivity;
import com.shuqi.controller.R;
import com.shuqi.database.model.BookInfo;

/**
 * 搜索主页标签列表适配器
 * 
 * @author linyuren
 * 
 */
public class BookSearchLabellistRealAdapter extends BaseAdapter {

    private BookSearchParentActivity mContext;

    /** 存储对象集合 */
    private List<BookInfo> searchLabelInfoData;

    /** 构造 */
    public BookSearchLabellistRealAdapter(BookSearchParentActivity context, List<BookInfo> data) {
        this.mContext = context;
        this.searchLabelInfoData = data;
    }

    public void setRealAdapter(List<BookInfo> data) {
        this.searchLabelInfoData = data;
    }

    @Override
    public int getCount() {
        return searchLabelInfoData == null ? 0 : searchLabelInfoData.size();
    }

    @Override
    public BookInfo getItem(int position) {
        return this.searchLabelInfoData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView =
                    LayoutInflater.from(mContext).inflate(R.layout.item_act_booksearch_labellist,
                            null);
            holder.listName = (TextView) convertView.findViewById(R.id.search_labellist_item);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        BookInfo slInfo = this.searchLabelInfoData.get(position);
        if (slInfo != null) {
            holder.listName.setText(slInfo.getBookName()); // 获取标签名称
        }
        return convertView;
    }

    private static class ViewHolder {
        public TextView listName;// 名称

    }
}
